package fi.iki.joker.mobilogger.img;

import android.util.Log;
import fi.iki.joker.mobilogger.blogs.BlogConfigConstants.BlogInterfaceType;
import fi.iki.joker.mobilogger.img.ImageRepositoryConstants.ImageRepositoryType;

/**
 * Serves singleton instances of image repository interfaces to callers.
 * Again, may be an overgeneralization for a mobile app but originally I would like to keep the
 * coupling as loose as possible. 
 * @author juhak
 *
 */

public class ImageRepoInterfaceFactory {

	private static final String TAG = "BlogInterfaceFactory";
	
	static ImageRepository instance;
	
	public static ImageRepository getInstance(ImageRepositoryType type) {
		if(type == ImageRepositoryConstants.ImageRepositoryType.FLICKR) {
			if(instance == null || !(instance instanceof FlickrInterface)) {
				instance = new FlickrInterface();
				Log.d(TAG,"Returning an instance of FlickInterface...");
			}
			return instance;
		} else if(type == ImageRepositoryConstants.ImageRepositoryType.PICASA_WEB) {
			if(instance == null || !(instance instanceof PicasaInterface)) {
				instance = new PicasaInterface();
				Log.d(TAG,"Returning an instance of PicasaInterface...");
			}
		} else {
			Log.e(TAG,"Tried to instantiate an unsupported BlogInterface type!");
			return null;
		}
		return instance;
	}
	
}
